package com.example.common.entity;

import jakarta.persistence.*;
import lombok.Data;

import java.math.BigInteger;
import java.time.LocalDateTime;

@Entity
@Table(name = "sys_dict_detail")
@Data
public class SysDictDetail {
    @Id
    @Column(name = "detail_id", nullable = false)
    private BigInteger detailId;
    
    @ManyToOne
    @JoinColumn(name = "dict_id", referencedColumnName = "dict_id")
    private SysDict sysDict;
    
    @Column(nullable = false)
    private String label, value;
    
    @Column(name = "dict_sort")
    private Integer dictSort;
    
    // create_by
    @ManyToOne
    @JoinColumn(name = "create_by", referencedColumnName = "username")
    private SysUser creator;
    
    // update_by
    @ManyToOne
    @JoinColumn(name = "update_by", referencedColumnName = "username")
    private SysUser updator;
    
    @Column(name = "create_time")
    private LocalDateTime createTime;
    
    @Column(name = "update_time")
    private LocalDateTime updateTime;
    
    public BigInteger getDetailId() {
        return detailId;
    }
    
    public void setDetailId(BigInteger detail_id) {
        this.detailId = detailId;
    }
    
    @Transient
    public BigInteger getDictId() {
        return sysDict.getDictId();
    }
    
    public void setSysDict(BigInteger dictId) {
        SysDict dict = new SysDict();
        dict.setDictId(dictId);
        this.sysDict = dict;
    }
    
    public String getLabel() {
        return label;
    }
    
    public void setLabel(String label) {
        this.label = label;
    }
    
    public String getValue() {
        return value;
    }
    
    public void setValue(String value) {
        this.value = value;
    }
    
    public Integer getDictSort() {
        return dictSort;
    }
    
    public void setDictSort(Integer dictSort) {
        this.dictSort = dictSort;
    }
    
    @Transient
    public String getCreateBy() {
        return creator.getUsername();
    }
    
    public void setCreateBy(String createBy) {
        SysUser user = new SysUser();
        user.setUsername(createBy);
        this.creator = user;
    }
    
    @Transient
    public String getUpdateBy() {
        return updator.getUsername();
    }
    
    public void setUpdateBy(String updateBy) {
        SysUser user = new SysUser();
        user.setUsername(updateBy);
        this.updator = user;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }
}
